package com.examples {
	import com.greensock.TweenMax;
	import com.greensock.plugins.TintPlugin;
	import com.greensock.plugins.TweenPlugin;

	import flash.display.Loader;
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.net.URLLoader;
	import flash.net.URLRequest;

	TweenPlugin.activate([TintPlugin]);
	public class ArrowButton extends Sprite {
		private	var _xml : XML;
		private	var _xmlList : XMLList;
		private	var _xmlLoader : URLLoader = new URLLoader();
		private	var _container : MovieClip = new MovieClip();
		private	var _imageLoader : Loader;

		public function ArrowButton() {
			makeArrowButton();

			addEventListener(MouseEvent.MOUSE_OVER, mouseOverHandler);
			addEventListener(MouseEvent.MOUSE_OUT, mouseOutHandler);
		}

		public function makeArrowButton() : void {
			_xmlLoader.load(new URLRequest("xml/images.xml"));
			_xmlLoader.addEventListener(Event.COMPLETE, xmlLoaded);
		}

		private function xmlLoaded(event : Event) : void {
			_xml = XML(event.target.data);
			_xmlList = _xml.children();
			_imageLoader = new Loader();
			_imageLoader.load(new URLRequest(_xmlList[1].attribute("thumb")));
			_container.buttonMode = true;
			_container.addChild(_imageLoader);
			addChild(_container);
		}

		public function mouseOverHandler(event : MouseEvent) : void {
			TweenMax.to(event.currentTarget, .3, {alpha:.5});
		}

		public function mouseOverHandlerRemove() : void {
			buttonMode = false;
			removeEventListener(MouseEvent.MOUSE_OUT, mouseOverHandler);
			TweenMax.to(this, .3, {alpha:.5});
		}

		public function mouseOverHandlerAdd() : void {
			addEventListener(MouseEvent.MOUSE_OVER, mouseOverHandler);
		}

		public function mouseOutHandler(event : MouseEvent) : void {
			TweenMax.to(event.currentTarget, .3, {alpha:1});
		}

		public function arrowBtnDispose() : void {
			_container.buttonMode = false;
			removeEventListener(MouseEvent.MOUSE_OUT, mouseOutHandler);
			removeEventListener(MouseEvent.MOUSE_OVER, mouseOverHandler);
			TweenMax.to(this, .3, {alpha:.5});
		}

		public function arrowBtnAdd() : void {
			addEventListener(MouseEvent.MOUSE_OUT, mouseOutHandler);
			addEventListener(MouseEvent.MOUSE_OVER, mouseOverHandler);
			TweenMax.to(this, .3, {alpha:1});
			buttonMode = true;
		}
	}
}
